<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/30
  Time: 8:45
  To change this template use File | Settings | File Templates.
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
</head>



<body>
<div  class="layui-container" >
<table class="layui-table">



    <thead>
        <tr>
            <th></th>
    <%--        <th>ID</th>--%>
            <th>姓名</th>
            <th>爱好</th>
            <th>地址</th>
            <th>操作</th>
            <th><a href="Logout"><button type="button" class="layui-btn-warm layui-btn" style="float: right;margin: 20px 0px 20px 5px" >注销</button></a></th>
            <th><button type="button" class="layui-btn layui-btn-danger" style="float: right;margin: 20px 5px" onclick="deleteById()">删除</button></th>
            <th><a href="addStudent.do"><button type="button" class="layui-btn" style="float: right;margin: 20px 5px" >添加</button></a></th>


        </tr>

    </thead>

    <tbody>
        <c:forEach var="stu" items="${students}" varStatus="status">
            <tr>
                <td>
                    <input type="checkbox" name="sid" class="sid" value="${stu.sid}">
                </td>
<%--                <td>${stu.sid}</td>--%>
                <td>${stu.sname}</td>
                <td>
                    <c:forEach var="hobby" items="${stu.hobbyList}" varStatus="status">
                        <c:if test="${hobby.isSelect>0}">
                            ${hobby.hname}
                        </c:if>
                    </c:forEach>
                </td>
                <td>
                    <c:forEach var="cla" items="${classesList}" varStatus="status">
                        <c:if test="${stu.cid==cla.cid}">
                            ${cla.cname}
                        </c:if>
                    </c:forEach>
                </td>
                <td>

                    <form action="updateStudent.do" method="get" style="width: 100px">
                        <input type="hidden" name="sid" value="${stu.sid}">
                        <button type="submit" class="layui-btn layui-btn-normal">修改</button>
                    </form>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>
    <form action="delStudent.do" id="idFrom" method="post">
        <input type="hidden" name="idArray">
    </form>
    <input type="hidden" class="pwd" th:value="${pwd}">
</div>
<script src="js/jquery-3.2.1.slim.min.js"></script>
<script>
    function deleteById(){
        //jquery获取复选框值
        var chk_value =[];
        $('input[name="sid"]:checked').each(function(){
            chk_value.push($(this).val());
        });
        if (chk_value.length==0){
            alert('请在前面打钩进行删除！');
            return;
        }
        if (!confirm("确定删除吗！")){
            return;
        }
        $('input[name="idArray"]').val(chk_value.toString());
        $('#idFrom').submit();
    }
</script>
</body>
</html>
